﻿@using System.Data
@using LiuYan.Web.Areas.Admin.Controllers
@{
    ViewBag.Title = "";
    Layout = "~/Areas/Admin/Views/Shared/AdminLayout.cshtml";
    //DataSet table = ViewData["menudata"] as DataSet;
    var table = ViewData["pmenu"] as DataTable;
}
<style>
    *{overflow-y:auto;}
</style>
<div class="searchpanel">
    <div class="seatchtool">
        <div class="operationtool">
            <a id="add">增加</a>
        </div>
    </div>
</div>
<table class="datatable">
    <tr>
        @*<th width="30">选择<input type="checkbox" id="checkall" /></th>*@
        <th width="130">父级菜单</th>
        <th width="130">子菜单</th>
        <th width="200">跳转地址</th>
        <th width="100">创建时间</th>
        <th width="50">序号</th>
        <th width="300">备注</th>
        <th width="200">操作</th>
        <th></th>
    </tr>
    <tbody id="list">
        @{
            foreach (DataRow row in table.Rows)
            {
                <tr>
                    <td>@row["Name"]</td>
                    <td>--</td>
                    <td>@row["Url"]</td>
                    <td>@Convert.ToDateTime(row["Date"]).ToString("yyyy-MM-dd")</td>
                    <td>@row["Order"]</td>
                    <td>@row["Remark"]</td>
                    <td><a class="ope_bt" onclick="del('@row["Id"]')">删除</a><a class="ope_bt" onclick="edit('@row["Id"]')">修改</a></td>
                    <td></td>
                </tr>
            MenuController menuController=new MenuController();
            var table1 = menuController.GetCmenu(Convert.ToInt32(row["Id"]));
            foreach (DataRow row1 in table1.Rows)
                {
                    if (row["Id"].ToString() == row1["Pid"].ToString())
                    {
                        <tr>
                            @*<td><input type="checkbox" value="@row1["Id"]" /></td>*@
                            <td>--</td>
                            <td>@row1["Name"]</td>
                            <td>@row1["Url"]</td>
                            <td>@Convert.ToDateTime(row1["Date"]).ToString("yyyy-MM-dd")</td>
                            <td>@row1["Order"]</td>
                            <td>@row1["Remark"]</td>
                            <td><a class="ope_bt" onclick="del('@row1["Id"]')">删除</a><a class="ope_bt" onclick="edit('@row1["Id"]')">修改</a></td>
                            <td></td>
                        </tr>
                    }
                }
            }

        }
    
    </tbody>
</table>
<div style="width: 100%;height: 100px;"></div>
<script>

    //选择全部
    $("#checkall").click(function () {
        if ($("#checkall").attr("checked")) {
            $("#list input[type=checkbox]").attr("checked", "true");
        } else {
            $("#list input[type=checkbox]").removeAttr("checked");
        }
    });

    
    //查询
    //$("#search").click(function () {
    //    getlist(0);
    //});


    //删除
   function del (id) {
      
        if (confirm("确定删除数据吗？")) {
            $.post("@Url.Action("Del")", { id: id }, function (row) {
                if (row > 0) {
                    location.reload();
                } else if(row==-1){
                    alert("该菜单下存在子级菜单，不能删除！");
                }
            });
        }

    }

    //修改
function edit (id) {
    
        if (id == 0) {
            alert("请选择要修改的数据！");
        } else {
            location.href = "@Url.Action("Window")" + "/" + id;
        }
    }

    //添加
    $("#add").click(function () {
        location.href = "@Url.Action("Window",new {id=0})";
    });
</script>